﻿/* 程序名：GetImageInfo.cpp
功能：从磁盘中读入图像文件，并将图像的各种信息显示在屏幕上
作者：胡斌
日期：2010-8-10
*/

#include "cv.h"
#include "highgui.h"
#include <iostream.h>

void main()
{
	IplImage *src_img =cvLoadImage("lena.jpg",-1);	//读入图像
	IplImage *dst_img;
	
	cout<<"******************************"<<endl<<endl;
	cout<<"The information"<<endl<<endl;
	
	cout<<"Size:"<<src_img->nSize<<endl;			//这个结构体的大小
	
	cout<<"ID:"<<src_img->ID<<endl;					//版本
	
	cout<<"Channels:"<<src_img->nChannels<<endl;	//图像通道数
	
	cout<<"Dataorder："<<src_img->dataOrder<<endl;	//交叉存取颜色通道
	
	cout<<"Original："<<src_img->origin<<endl;		//图像数据分布结果
	
	cout<<"Depth:"<<src_img->depth<<endl;			//图像色深
	
	cout<<"Width"<<src_img->width<<endl;			//图像宽度像素
	
	cout<<"Height"<<src_img->height<<endl;			//图像高度像素
	
	cout<<"ROI:"<<src_img->roi<<endl;				//未指定ROI区域指针
	
	cout<<"WidthStep"<<src_img->widthStep<<endl;	//排列的图像行大小
	
	cout<<"ImageSize"<<src_img->imageSize<<endl;	//图像数据大小
	
	/*输出图像的一块RGB值*/
	for (int i=0;i<200;i+=3)
	{
		cout<<(int)(uchar)src_img->imageData[i];	//Blue
		cout<<",";
		cout<<(int)(uchar)src_img->imageData[i+1];	//Green
		cout<<",";
		cout<<(int)(uchar)src_img->imageData[i+2]<<endl;//Red
	}
	
	dst_img=cvCreateImage(cvSize(src_img->width,src_img->height),
	src_img->depth,3);
	cvConvertImage(src_img,dst_img,CV_CVTIMG_FLIP);	//倒置图像
	cvNamedWindow("lena.jpg",CV_WINDOW_AUTOSIZE);
	cvNamedWindow("lenaflip.jpg",CV_WINDOW_AUTOSIZE);
	cvShowImage("lena.jpg",src_img);
	cvShowImage("lenaflip.jpg",dst_img);
	cvWaitKey(0);
	cvReleaseImage(&src_img);
	cvReleaseImage(&dst_img);
} 